package com.efast.dmom.mes.bean;

import java.util.Comparator;

import com.efast.dmom.mes.bean.base.ConfigurationBaseBean;
import com.efast.dmom.mes.entity.ShiftItemEntity;

public class ShiftItem extends ConfigurationBaseBean<ShiftItemEntity> {

	private static final long serialVersionUID = -4124389036676046912L;
	
	public static Comparator<ShiftItem> sequenceComparator = new Comparator<ShiftItem>() {

		@Override
		public int compare(ShiftItem item1, ShiftItem item2) {

			if (item1 == null) {
				return -1;
			}
			if (item2 == null) {
				return 1;
			}

			ShiftItemEntity entity1 = item1.getInnerData();
			ShiftItemEntity entity2 = item2.getInnerData();

			if (entity1.getShiftItemSequence() > entity2.getShiftItemSequence()) {
				return 1;
			}

			if (entity1.getShiftItemSequence() < entity2.getShiftItemSequence()) {
				return -1;
			}

			if (entity1.getShiftItemSequence() == entity2.getShiftItemSequence()) {

				if (entity1.getStartTime().isBefore(entity2.getStartTime()))
					return -1;
				else if (entity1.getStartTime().isAfter(entity2.getStartTime())) {
					return 1;
				}
			}
			return 0;
		}
	};
	
	public static Comparator<ShiftItem> timeComparator = new Comparator<ShiftItem>() {

		@Override
		public int compare(ShiftItem item1, ShiftItem item2) {

			if (item1 == null) {
				return -1;
			}
			if (item2 == null) {
				return 1;
			}

			ShiftItemEntity entity1 = item1.getInnerData();
			ShiftItemEntity entity2 = item2.getInnerData();

			if (entity1.getStartTime() == null) {
				return -1;
			}

			if (entity1.getStartTime() == null) {
				return 1;
			}

			if (entity1.getStartTime().isBefore(entity2.getStartTime()))
				return 1;
			else if (entity1.getStartTime().isAfter(entity2.getStartTime())) {
				return -1;
			}
			return 0;
		}
	};
	
}
